package com.swift.authority.application.config.security;

import com.swift.authority.common.constant.CommonConstant;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @author Administrator
 * @version 1.0
 * @description jwt储存
 * @date 2022/07/03  12:37
 */
@Configuration
public class JwtTokenConfig {

    /**
     * 作用：将oauth2生成的token转换成jwt可以识别的token
     * @return
     */
    @Bean
    public TokenStore jwtTokenStore(){
        return new JwtTokenStore(jwtAccessTokenConverter());
    }


    /**
     * 在转换器中配置秘钥
     * @return JwtAccessTokenConverter
     */
    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter(){
        JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
        //设置jwt秘钥
        jwtAccessTokenConverter.setSigningKey(CommonConstant.JWT_TOKEN_SECRET);
        return jwtAccessTokenConverter;
    }

    /**
     * 配置jwt增强内容
     * @return JwtTokenEnhancer
     */
    @Bean
    public JwtTokenEnhancer jwtTokenEnhancer(){
        return new JwtTokenEnhancer();
    }
}
